<?php

/**
 * This is the model class for table "medco.addresses".
 *
 * The followings are the available columns in table 'medco.addresses':
 * @property integer $addressId
 * @property string $houseNumber
 * @property string $streetName
 * @property string $addressLine1
 * @property string $locality
 * @property string $city
 * @property string $postCode
 * @property string $country
 * @property string $createdBy
 * @property string $createdTime
 * @property string $updatedBy
 * @property string $updatedTime
 *
 * The followings are the available model relations:
 * @property Hospital[] $hospitals
 * @property Patientaddress[] $patientaddresses
 * @property Staffaddress[] $staffaddresses
 */
class Addresses extends MedcoCActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Addresses the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'medco.addresses';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('houseNumber, streetName, city', 'required'),
			array('houseNumber, createdBy, updatedBy', 'length', 'max'=>10),
			array('streetName, addressLine1, locality, city, country', 'length', 'max'=>100),
			array('postCode', 'length', 'max'=>6),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('addressId, houseNumber, streetName, addressLine1, locality, city, postCode, country, createdBy, createdTime, updatedBy, updatedTime', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'hospitals' => array(self::HAS_MANY, 'Hospital', 'hospitalAddressId'),
			'patientaddresses' => array(self::HAS_MANY, 'Patientaddress', 'addressId'),
			'staffaddresses' => array(self::HAS_MANY, 'Staffaddress', 'addressId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'addressId' => 'Address',
			'houseNumber' => 'House Number',
			'streetName' => 'Street Name',
			'addressLine1' => 'Address Line1',
			'locality' => 'Locality',
			'city' => 'City',
			'postCode' => 'Post Code',
			'country' => 'Country',
			'createdBy' => 'Created By',
			'createdTime' => 'Created Time',
			'updatedBy' => 'Updated By',
			'updatedTime' => 'Updated Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('addressId',$this->addressId);
		$criteria->compare('houseNumber',$this->houseNumber,true);
		$criteria->compare('streetName',$this->streetName,true);
		$criteria->compare('addressLine1',$this->addressLine1,true);
		$criteria->compare('locality',$this->locality,true);
		$criteria->compare('city',$this->city,true);
		$criteria->compare('postCode',$this->postCode,true);
		$criteria->compare('country',$this->country,true);
		$criteria->compare('createdBy',$this->createdBy,true);
		$criteria->compare('createdTime',$this->createdTime,true);
		$criteria->compare('updatedBy',$this->updatedBy,true);
		$criteria->compare('updatedTime',$this->updatedTime,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}